﻿@using Entity.ProjectEnt;
@{
    ViewBag.Title = "JieCheIndex";
    Layout = "~/Views/Shared/_Index.cshtml";
    List<CustomerAndThingsNameEntity> kehulist = ViewBag.kehulist;
    List<CustomerAndThingsNameEntity> pingming = ViewBag.pingminglist;
}
<script src="~/Content/js/datepicker/WdatePicker.js"></script>
<script>

    $(function () {
        gridList();
    });
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/Project/Carriage/GetGridJsonArrive",
            height: $(window).height() - 96,
            colModel: [
                { label: "主键", name: "F_Id", hidden: true, key: true },
                {
                    label: '车号', name: 'CarriageID', width: 80, align: 'left'
                },
                {
                    label: '车型', name: 'CarType', width: 80, align: 'left'
                },
                {
                    label: '载重', name: 'Capacity', width: 80, align: 'left'
                },
                {
                    label: '所属股道', name: 'PathWay', width: 80, align: 'left'
                },
                {
                    label: '品名', name: 'ThingsName', width: 80, align: 'left'
                },
                //{
                //    label: '封号', name: 'Fenhao', width: 80, align: 'center'
                //},
                //{
                //    label: '到站', name: 'ArriveStation', width: 80, align: 'center'
                //},
                //{
                //    label: '件数', name: 'UnitNumber', width: 80, align: 'center'
                //},
                {
                    label: '重量', name: 'Weight', width: 80, align: 'center'
                },
                {
                    label: '客户', name: 'Customers', width: 80, align: 'center'
                },
                {
                    label: '到达时间', name: 'ArriveTime', width: 150, align: 'left'
                },
                {
                    label: '备注', name: 'Remark', width: 150, align: 'left'
                }
            ],
            pager: "#gridPager",
            sortname: 'ArriveTime desc',
            viewrecords: true


        });
        $("#btn_search").click(function () {
            GetCarInfo();
            $gridList.jqGrid('setGridParam', {
                postData: {
                    keyword: $("#txt_keyword").val(),
                    StartTime: $("#sTime").val(),
                    EndTime: $("#eTime").val(),
                    carId: $("#txt_carId").val(),
                    customerName: $("#txt_customerName").val()
                }
            }

            ).trigger('reloadGrid');
        });
        $("#btn_export").click(function () {
            var keyword = $("#txt_keyword").val();
            var StartTime = $("#sTime").val();
            var EndTime = $("#eTime").val();
            var carId = $("#txt_carId").val();
            var customerName = $("#txt_customerName").val();
            window.location.href = "/Project/Carriage/GetExportExcell?keyword=" + keyword + "&StartTime=" + StartTime + "&EndTime=" + EndTime
                + "&carId=" + carId + "&customerName=" + customerName;
        })
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "添加股道",
            url: "/Project/Pathway/Form",
            width: "650px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    //获取总车数和总吨数
    function GetCarInfo() {
        $.ajax({
            url: '/Project/Carriage/GetTotalCarInfo?keyword=' + $("#txt_keyword").val() + "&StartTime=" + $("#sTime").val() + "&EndTime=" + $("#eTime").val() + "&carId=" + $("#txt_carId").val() + "&customerName=" + $("#txt_customerName").val(),
            data: {},
            dataType: "json",
            type: "Get",
            success: function (data) {
                if (data != "") {
                    //alert(data);
                    var span = document.getElementById("carNum");
                    span.innerText = data.CarNum;
                    var span2 = document.getElementById("totalWeight");
                    span2.innerText = data.TotalWeight;
                }
            }
        });
    }

    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Form",
            title: "修改股道信息",
            url: "/Project/Pathway/Form?keyValue=" + keyValue,
            width: "650px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {

        $.deleteForm({
            url: "/Project/Pathway/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().F_Id },
            success: function () {
                $.currentWindow().$("#gridList").resetSelection();
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        });
    }
    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Details",
            title: "查看股道详情",
            url: "/Project/Pathway/Details?keyValue=" + keyValue,
            width: "1000px",
            height: "720px",
            btn: null
        });
    }

</script>

<div class="topPanel">
    <div class="toolbar">

        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>

        <div class="btn-group">
            总车辆:
        </div>
        <div class="btn-group">
            <span id="carNum">
                0
            </span>
        </div>
        <div class="btn-group">
            总吨数(吨):
        </div>
        <div class="btn-group">
            <span id="totalWeight">
                0
            </span>
        </div>

        <div class="btn-group">
            @*<a id="NF-add" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新增股道</a>*@
        </div>
        @*<div class="operate">*@
        @*<ul class="nav nav-pills">*@
        @*<li class="first">已选中<span>1</span>项</li>*@
        @*<li><a id="NF-edit" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改股道</a></li>
            <li><a id="NF-delete" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除股道</a></li>*@
        @*<li><a id="NF-Details" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看详情</a></li>*@
        @*<li class="split"></li>*@
        @*</ul>*@
        @*<a href="javascript:;" class="close"></a>*@
        @*</div>*@
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td class="formValue">
                    <select class="btn-group"id="txt_keyword" style="padding: 6px; background-image: none; border: 1px solid ; border-radius: 4px;">
                        @if (pingming.Count > 0)
                        {
                            <option value="">所有品名</option>
                            foreach (var item in pingming)
                            {
                                <option value="@item.Name">@item.Name</option>
                            }
                        }
                    </select>
                </td>
                <td class="formValue">
                    <select class="btn-group"id="txt_customerName" style="padding: 6px; background-image: none; border: 1px solid ; border-radius: 4px;">
                        @if (kehulist.Count > 0)
                        {
                            <option value="">所有客户</option>
                            foreach (var item in kehulist)
                            {
                                <option value="@item.Name">@item.Name</option>
                            }
                        }
                    </select>
                </td>
                <td>
                    <div class="input-group" style="padding-left:11px;padding-right:10px;">
                        <input id="txt_carId" type="text" class="form-control" placeholder="按照车号模糊搜索" style="width: 110px; margin-right:20px;">
                        <input id="sTime" name="sTime" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" placeholder="输入开始查询时间" style="width: 150px; margin-right:20px;">
                        <input id="eTime" name="eTime" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" placeholder="输入结束查询时间" style="width: 150px; margin-right:20px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary active"><i class="fa fa-search"></i></button>
                            <button id="btn_export" style="margin-left:20px;" type="button" class="btn  btn-primary ">
                                <span class="tab">
                                    导
                                </span>
                            </button>
                        </span>
                        @*<span id="txt_carNum" style="width:50px"> 总车数：</span>*@
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<style>
    table tr td {
        padding-left: 15px;
    }
</style>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
